package hn.cch.framework.disruptor;

import com.lmax.disruptor.RingBuffer;

public class StringEventProducer {

    public final RingBuffer<StringEvent> ringBuffer;

    public StringEventProducer(RingBuffer<StringEvent> ringBuffer) {
        this.ringBuffer = ringBuffer;
    }

    public void onData(String data) {
        long sequence = ringBuffer.next();
        try {
            StringEvent stringEvent = ringBuffer.get(sequence);
            stringEvent.setValue(data);
        } finally {
            System.out.println("StringEventProducer.onData:" + data);
            ringBuffer.publish(sequence);
        }
    }

}
